package stud.mpgame.network.util;

import org.apache.mina.core.session.IoSession;

import stud.mpgame.network.MessageDescription;

/**
 * @author f.pavel91@gmail.com
 * @version 1.0
 */
public class MessageFilter {

    private MessageDescription messageDescription;
    private IoSession session;

    public MessageFilter() {
        this.messageDescription = null;
        this.session = null;
    }

    public MessageFilter(IoSession session) {
        this.messageDescription = null;
        this.session = session;
    }

    public MessageFilter(MessageDescription messageDescription) {
        this.messageDescription = messageDescription;
        this.session = null;
    }

    public MessageFilter(MessageDescription messageDescription, IoSession session) {
        this.messageDescription = messageDescription;
        this.session = session;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;

        MessageFilter that = (MessageFilter) o;

        boolean equalityOfDescription = (messageDescription != null ? (messageDescription.equals(that.messageDescription)) : that.messageDescription == null);
        boolean equalityOfSession = (session != null ? session.equals(that.session) : that.session == null);

        return equalityOfDescription && equalityOfSession;
    }

    @Override
    public int hashCode() {
        int result = messageDescription != null ? messageDescription.hashCode() : 0;
        result = 31 * result + (session != null ? session.hashCode() : 0);
        return result;
    }

    public MessageDescription getMessageDescription() {
        return messageDescription;
    }

    public IoSession getSession() {
        return session;
    }

}
